library(Binomial)

How to use the Binomial Package

The pacakage "binomial" is created to simulate doing a binomial experiment and implements functions for calculating the probabilities of a Binomial random variable, and related calculations such as the probability distribution, the expected value, variance, etc.

This document introduces you to binomial's basic set of tools, and shows you how to apply them.

Function bin_choose()

The 'bin_choose' function calculates the number of combinations in which k success can occur in n trials. The function takes the arguments n and k, and then assuming k and n are integers and n>k, returns the number of combinations in which k successes can occur in n trials.

Examples
bin_choose(n=5,k=2)
bin_choose(5,0)
bin_choose(5,1:3)

Function bin_probability()

The "bin_probability" function takes three arguments:success, trials, and prob. This function has built in checkers to ensure that the inputs are the appropriate length and type. If any are not, the function will return an error. When used correctly, the function returns the probability of getting a certain amount of successes in a given number of trials

Examples:
# probability of getting 2 successes in 5 trials
# (assuming prob of success = 0.5)
bin_probability(success = 2, trials = 5, prob = 0.5)

# probabilities of getting 2 or less successes in 5 trials
# (assuming prob of success = 0.5)
bin_probability(success = 0:2, trials = 5, prob = 0.5)

# 55 heads in 100 tosses of a loaded coin with 45% chance of heads
bin_probability(success = 55, trials = 100, prob = 0.45)

Function bin_distribution()

The "bin_distribution()" function calculates the probability of getting successes in a given number of trials, returning a data frame of the class "bindis" and "data.frame". The returned data frame has two columns with successes in the first column and probability in the second column. The function takes two inputs: trials and prob.

Examples:
# binomial probability distribution
bin_distribution(trials = 5, prob = 0.5)

The function includes a built in method to plot objects of the class "bindis" in a barplot.

Examples:
# plotting binomial probability distribution
dis1 <- bin_distribution(trials = 5, prob = 0.5)
plot(dis1)

Function bin_cumulative()

The "bin_cumulative()" function takes two arguments--trials and prob--and returns a data frame with the probability distribution and the cumulative probabilities. The data frame is of the class "bincum" and "data.frame"

Examples:
# binomial cumulative distribution
bin_cumulative(trials = 5, prob = 0.5)

The function includes a built in method to plot the cumulative probabilities vs successes of the object of the class "bincum" in a line graph.

Examples:
# plotting binomial cumulative distribution
dis2 <- bin_cumulative(trials = 5, prob = 0.5)
plot(dis2)

Function bin_variable()

The function "bin_variable" returns the number of trials and probability of success in an object with the class "binvar." The function takes two arguments: trials and prob. The function has a method "print.binvar()" to nicely print the returned object of class "binvar" in a way that is easy to read

Examples:
bin1 <- bin_variable(10,0.3)
bin1

The function also has methods "summary.binvar" which returns an object that can be printed nicely with the method "print.summary.binvar" to print the summary of the function

Examples:
bin1 <- bin_variable(10, 0.3)
binsum1 <- summary(bin1)
binsum1

Functions of Measures

bin_mean, bin_variance, bin_mode, bin_skewness, bin_kurtosis

These functions all take two arguments, trials and prob, checking if they are valid then calculating the relevant results.

Examples:
bin_mean(10,.3)
bin_variance(10,.3)
bin_mode(10,.3)
bin_skewness(10,.3)
bin_kurtosis(10,.3)


annabardin/Workout03 documentation built on May 4, 2019, 12:54 a.m.